<?php
/* Global variables - DO NOT CHANGHE THESE CONFIGURATION!!! */

/* MySQL database */
$MYSQL_DB_NAME = 'localbadges';

/* MySQL query */

/* Badges retrivial */
$BADGES_QUERY = "SELECT `categoria`.`idCategoria` AS `categoriaId`, `categoria`.`nome` AS `categoryName`, `badgeId`, `badge`.`nome` AS `badgeName`, `badge`.`descrizione` " . 
				"AS `descrizione`, `badge`.`immagine` AS `immagine`, `tags`, `condivisa`, `issuerId`, " . 
				"`issuer`.`nome` AS `issuerName` FROM `categoria` JOIN `badge` JOIN `issuer` ON " . 
				"`categoria`.`idCategoria`=`badge`.`idCategoria` AND `idIssuer`=`issuerId`";

/* Specific badge retrivial */
$BADGE_QUERY = $BADGES_QUERY . " WHERE `badgeId`=\"%s\"";

/* Get badge criteria */
$GET_BADGE_CRITERIA = "SELECT `type`, `content` FROM `badge_criteria` WHERE `badgeId`=\"%s\"";

/* User INSERT query string */
$INSERT_USER = "INSERT INTO `user`(`cognome`, `nome`, `email`, `password`, `admin`, `idIssuer`) VALUES " . 
		"(\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\")";

/* Badge INSERT query string */
$INSERT_BADGE = "INSERT INTO `badge`(`nome`, `descrizione`, `immagine`, `tags`, `idIssuer`, `condivisa`, `idCategoria`) VALUES " . "
		(\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\")";

/* Baked Badge INSERT query string */
$INSERT_BAKED_BADGE = "INSERT INTO `baked_badge`(`bakedUid`, `bakedUser`, `bakedBadge`, " .
		"`verifyType`, `verifyUrl`, `issuedOn`, `image`, `evidence`, " .
		"`expires`, `uploaded`, `issuerId`) VALUES (\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", " . 
		"FROM_UNIXTIME(%s), \"%s\", \"%s\", FROM_UNIXTIME(%s), FALSE, \"%s\")";

/* Category INSERT query string */
$INSERT_CATEGORY = "INSERT INTO `categoria`(`nome`, `categoriaPadre`) VALUES " . "
(\"%s\", \"%s\")";

/* Criteria INSERT query string */
$INSERT_CRITERIA = "INSERT INTO `badge_criteria`(`badgeId`, `type`, `content`) VALUES " . "
(\"%s\", \"%s\", \"%s\")";

/* Category DELETE query string */
$REMOVE_CATEGORY = "DELETE FROM `categoria` WHERE `idCategoria`=\"%s\"";

/* User earned badges */
$EARNED_BADGES = "SELECT `verifyUrl`, `evidence`, `uploaded`, UNIX_TIMESTAMP(`expires`) AS `expires`, " . 
		"`immagine` FROM `baked_badge` INNER JOIN `badge` ON `bakedBadge`=`badgeId` WHERE " . 
		"`bakedUser`=\"%s\"";

$EARNED_BADGES_2 = "SELECT `categoria`.`idCategoria` AS `categoriaId`, `categoria`.`nome` AS `categoryName`, `badge`.`badgeId` AS `badgeId`, `badge`.`nome` AS `badgeName`, `badge`.`descrizione` " . 
				"AS `descrizione`, `badge`.`immagine` AS `immagine`, `tags`, `condivisa`, `bakedUser` AS `userId`, `verifyUrl`, UNIX_TIMESTAMP(`issuedOn`) AS `issuedOn`, `evidence`, UNIX_TIMESTAMP(`expires`) AS `expires`, `uploaded`, `baked_badge`.`issuerId` AS `issuerId`, " . 
				"`issuer`.`nome` AS `issuerName` FROM `categoria` JOIN `badge` JOIN `baked_badge` JOIN `issuer` ON " . 
				"`categoria`.`idCategoria`=`badge`.`idCategoria` AND `badge`.`badgeId`=`baked_badge`.`bakedBadge` AND `baked_badge`.`issuerId`=`issuer`.`issuerId` WHERE " . 
		"`bakedUser`=\"%s\"";

/* Badge category id */
$CATEGORY_BADGE = "SELECT `badgeId` FROM `badge` WHERE `idCategoria`=\"%s\"";

/* Update badge category id */
$UPDATE_CATEGORY="UPDATE `badge` SET `idCategoria`=\"%s\" WHERE `badgeId`=\"%s\"";

/* Verify if a user has already a badge */
$VERIFY_ISSUE = "SELECT `bakedId` FROM `baked_badge` WHERE `bakedUser`=\"%s\" AND " . 
		"`bakedBadge`=\"%s\"";

/* Verify if there is a user with a given email */
$VERIFY_EMAIL = "SELECT `userId` FROM `user` WHERE `email`=\"%s\"";

/* Verify if there is a badge with a given name */
$VERIFY_BADGE_NAME = "SELECT `badgeId` FROM `badge` WHERE `nome` LIKE \"%s\"";

/* Verify if there is a category with a given name */
$VERIFY_CATEGORY_NAME = "SELECT `idCategoria` FROM `categoria` WHERE `nome` LIKE \"%s\"";

/* Retrieve user informations to verify login credentials */
$VERIFY_LOGIN = "SELECT `userId`, `email`, `password`, `admin`, `idIssuer` FROM `user` WHERE `email`='%s'";

/* Retrieve user password - used for changing it */
$GET_USER_PASSWORD = "SELECT `password` FROM `user` WHERE `userId`=\"%s\"";

/* Update user password - used for changing it */
$UPDATE_USER_PASSWORD = "UPDATE `user` SET `password`=\"%s\" WHERE `userId`=\"%s\"";

/* Update badge status */
$UPDATE_BADGE_STATUS = "UPDATE `baked_badge` SET `uploaded`=%s WHERE `bakedUser`=\"%s\" " . 
		"AND `verifyUrl`='%s'";

/* Resources Paths */

/* Path to JSON files from php scripts folder */
$JSON_PATH_FROM_PHP = '../../json';

/* Path to image files from php scripts folder */
$IMG_PATH_FROM_PHP = '../../img';

/* Path to badges image files from php scripts folder */
$BADGE_IMG_PATH_FROM_PHP = $IMG_PATH_FROM_PHP . '/badges_png';

/* Path to baked badges image files from php scripts folder */
$BAKED_PATH_FROM_PHP = $IMG_PATH_FROM_PHP . '/baked_badges';

/* Path to JSON assertion files from php scripts folder */
$JSON_ASSERTIONS_PATH_FROM_PHP = $JSON_PATH_FROM_PHP . '/assertions';

/* Path to JSON badge files from php scripts folder */
$JSON_BADGES_PATH_FROM_PHP = $JSON_PATH_FROM_PHP . '/badges';

/* URLs */

/* Open Badge email converter WS */
$EMAIL_CONVERTER_WS_URL = 'http://beta.openbadges.org/displayer/convert/email';

/* Backpack URL */
$BACKPACK_URL = 'http://localhost:8888';

/* Open Badges baker WS */
$BAKER_WS_URL = $BACKPACK_URL . '/baker?assertion=';

/* Badges PNG images URL */
$BADGES_PNG_URL = $ISSUER_HOST . '/img/badges_png';

/* Baked Badges PNG images URL */
$BAKED_PNG_URL = $ISSUER_HOST . '/img/baked_badges';

/* JSON files URL */
$JSON_FILES_URL = $ISSUER_HOST . '/json';

/* JSON assertion files URL */
$JSON_ASSERTIONS_URL = $JSON_FILES_URL . '/assertions';

/* JSON badge files URL */
$JSON_BADGES_URL = $JSON_FILES_URL . '/badges';

/* Locations - to use in header() function */

/* Home */
$LOCATION_HOME = "Location: " . $ISSUER_HOST;

/* Login page */
$LOCATION_LOGIN = "Location: " . $ISSUER_HOST . "/login.php";

/* Forbidden page */
$LOCATION_FORBIDDEN = "Location: " . $ISSUER_HOST . "/forbidden.html";

/* Other settings */

/* Salt used to hash user passwords */
$PSW_SALT = "thisisthesaltyouusetohashuserpasswords";

/* Number of iterations in hashing user passwords */
$HASHING_ITERATIONS = 2;

/* Hash salt length (for email in assertions) */
$SALT_LENGTH = 6;

/* Issuer Time Zone (may be different from server time zone) */
$ISSUER_TIME_ZONE = 'CEST';

/* text/plain email headers */
$EMAIL_HEADERS = 'X-Mailer: PHP/' . phpversion();

/* text/html email headers */
$HTML_EMAIL_HEADERS = $EMAIL_HEADERS . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 
		'Content-type: text/html; charset=utf8' . "\r\n";

/* Earned badge email subject */
$BADGE_EARNED_SUBJECT = 'Congratulations! You have earned a badge!';

/* Earned badge email default content - format string */
$BADGE_EARNED_CONTENT = 'Congratulations!' . "\r\n" . 
						'You have just earned a badge from ' . $ISSUER_HOST . "\r\n" . 
						'You can download it from this URL: %s and then upload it from ' . 
						'your personal backpack at ' . $BACKPACK_URL;

/* Earned badge email HTML content - format string */
$BADGE_EARNED_HTML_CONTENT = '
		<html>
		<head>
			<title>Congratulations! You have earned a badge!</title>
		</head>
		<body>
			<p>Congratulations!</p>
			<p>You have just earned a badge from <a href="' . $ISSUER_HOST . '">' . 
			$ISSUER_HOST . '</a></p>
			<p>You can download it from this URL: <a href="%s">%s</a> and then ' . 
			'upload it from your personal backpack at <a href="' . $BACKPACK_URL . 
			'">' . $BACKPACK_URL . '</a></p>
		</body>
		</html>';

/* Earned badge email subject */
$REGISTERED_SUBJECT = 'Registration to OpenBadges';

/* Earned badge email HTML content - format string */
$REGISTERED_HTML_CONTENT = '
		<html>
		<head>
			<title>Registration to OpenBadges</title>
		</head>
		<body>
			<p>You have just been registered%s to the OpenBadges service of ' . 
			'<a href="' . $ISSUER_HOST . '">' . $ISSUER_HOST . '</a></p>
			<p>Use this email address as username and the password indicated below ' . '
			to login the system.</p>' . 
			'<p>Your password is: %s</p>' .
			'<p>You can change your password from your personal page on the site.</p>
		</body>
		</html>';

/* Badge upload button */
$UPLOAD_BUTTON = "<input type=\"button\" value=\"Aggiungi%s\" onclick=\"uploadBadges([%s], %s)\"/>";

/* Id for unspecified category */
$NO_CATEGORY = 3;
?>
